package net.fdukedom.epicurus.service.interaction;

import org.jdom.Document;
import org.jdom.Element;

/**
 * 
 * @author Alexander Kirakozov
 * 
 */
public class ResponseWriter extends Response {
	/**
	 * Constructor
	 */
	public ResponseWriter() {
		createDocument();
	}

	@Override
	public void createDocument() {
		Element rootElement = new Element(RESPONSE);

		Element resultElem = new Element(RESULT);
		rootElement.addContent(resultElem);

		doc = new Document();
		doc.setRootElement(rootElement);
	}

	/**
	 * Sets status
	 * 
	 * @value status
	 */
	public void setStatus(boolean value) {
		if (value) {
			updateRootChildElement(STATUS, STATUS_SUCCESS);
		} else {
			updateRootChildElement(STATUS, STATUS_FAILED);
		}
	}

	/**
	 * Sets message
	 * 
	 * @value message
	 */
	public void setMessage(String value) {
		updateRootChildElement(MESSAGE, value);
	}

	/**
	 * Sets result element
	 * 
	 * @param element
	 *            result element
	 */
	public void addResult(Element element) {
		setElement(RESPONSE_PREFIX + RESULT, element);
	}
}
